package www.sofn.com.shopping.cart;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import www.sofn.com.domain.R;
import www.sofn.com.shopping.cart.domain.vo.AddShoppingCartVO;
import www.sofn.com.shopping.cart.domain.vo.ShoppingCartGoodsInfoVO;
import www.sofn.com.shopping.cart.domain.vo.ShoppingCartOrderInfoVO;

import java.util.List;

@RestController
@Tag(name = "购物车")
@RequestMapping("/shopping_cart")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    @PostMapping("add_shopping_cart")
    @Operation(summary = "加入购物车")
    public R addShoppingCart(@RequestBody @Validated() AddShoppingCartVO addShoppingCartVO) {
        shoppingCartService.addShoppingCart(addShoppingCartVO);
        return R.ok();
    }

    @Operation(summary = "获取购车车商品信息")
    @GetMapping("/find_shopping_cart_goods_info")
    public R<List<ShoppingCartGoodsInfoVO>> finalShoppingCartGoodsInfo() {
        return R.ok(shoppingCartService.finalShoppingCartGoodsInfo());
    }

    @Operation(summary = "获取购车商品数量")
    @GetMapping("/get_shopping_cart_goods_num")
    public R<Long> getShoppingCartGoodsNum() {
        return R.ok(shoppingCartService.getShoppingCartGoodsNum());
    }


    @Operation(summary = "生成购物车订单信息")
    @PostMapping("/generate_shopping_cart_order_info")
    public R<ShoppingCartOrderInfoVO> generateShoppingCartOrderInfo(@RequestBody  List<String> ids){
        return R.ok(shoppingCartService.generateShoppingCartOrderInfo(ids));
    }

}
